package com.edie.customview.modular.mymvpusebase;

import android.os.Build;
import android.util.Log;

import com.edie.customview.data.entity.UserEntity;
import com.edie.customview.data.net.api.NetClient1;

import java.util.concurrent.TimeUnit;

import io.reactivex.Observable;
import io.reactivex.Observer;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.Disposable;
import io.reactivex.functions.Function;
import io.reactivex.schedulers.Schedulers;

/**
 * edie create on 2018/7/19
 */
public class MyMvpDemoModelImpl implements MyMvpDemoContract.IMyMvpModel {
    private static final String TAG = "MyMvpDemoModelImpl";

    @Override
    public Observable<String> loadMsg(String msgId) {
        String miei = "";
        String model = Build.MODEL;
        String username = "18135705969";
        String password = "123456";
        //以下是必须参数
        String device = "android";
        String deviceid = "";
        String time = String.valueOf(System.currentTimeMillis() / 1000);
        String version = "";
        //按ascii排序
        String hash = "22222";
        return NetClient1.getInstance()
                .createUserApi()
                .postLogin(device, deviceid, time, hash, version, miei, model, username, password)
                .delay(2, TimeUnit.SECONDS)
                .subscribeOn(Schedulers.io())
                .map(userEntity -> userEntity.msg + msgId)
                .observeOn(AndroidSchedulers.mainThread());
//                .subscribe(new Observer<UserEntity>() {
//                    @Override
//                    public void onSubscribe(Disposable d) {
//                        Log.d(TAG, "onSubscribe: ");
//                    }
//
//                    @Override
//                    public void onNext(UserEntity userEntity) {
//                        Log.d(TAG, "onNext: ");
//
//                    }
//
//                    @Override
//                    public void onError(Throwable e) {
//                        Log.e(TAG, "onError: ", e);
//                    }
//
//                    @Override
//                    public void onComplete() {
//                        Log.d(TAG, "onComplete: ");
//                    }
//                });
//        return Observable.just(msgId)
//                .subscribeOn(Schedulers.io())
//                .map(new Function<String, String>() {
//                    @Override
//                    public String apply(String s) throws Exception {
//                        return String.format("消息ID是%s", msgId);
//                    }
//                })
//                .observeOn(AndroidSchedulers.mainThread());
    }
}
